package com.hp.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.hp.ssm.entity.Role;
import com.hp.ssm.entity.User;
import com.hp.ssm.mapper.RoleMapper;
import com.hp.ssm.service.RoleService;
import com.hp.ssm.util.DBHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    RoleMapper roleMapper;


    @Override
    public List<User> selectAll(User user,Integer page,Integer limit) {
        if(page != null && limit != null) {
            PageHelper.startPage(page, limit);
        }
        return roleMapper.selectAll(user);
    }

    @Override
    public List<Map> getAuthority(Integer rid) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        return dbHelper.select("select p.*,IFNULL(rp.id,-1) ck from permissions p left join (select * from rolepermissions where rid = ?) rp on p.permissionsidNo=rp.permissionsidNo",rid);
    }

    @Override
    public int promotion(Integer aid) {
        return roleMapper.promotion(aid);
    }

    @Override
    public int demotion(Integer aid) {
        return roleMapper.demotion(aid);
    }

    @Override
    public List<Role> selectAll1(Role role, Integer page, Integer limit) {
        if(page != null && limit != null) {
            PageHelper.startPage(page, limit);
        }
        return roleMapper.selectAll1(role);
    }
}
